package com.families.controller;

import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.families.util.CheckUtil;

@Controller
public class SkipController {

	//添加日志
		private static final Logger logger = LoggerFactory.getLogger(SkipController.class);
		@Autowired
		private RedisTemplate redisTemplate;
	/**
	 * 登录页面跳转
	 * @return
	 */
		@RequestMapping("/")
		public String toLogin(HttpServletRequest request) {
			//判断是否有登录用户
			String header = request.getHeader("User-Agent");
			logger.info("用户来‘{}’端",header);
			boolean mobileDevice = CheckUtil.isMobileDevice(header);
			Subject currentUser = SecurityUtils.getSubject();
			if(mobileDevice) {
				if(currentUser.isAuthenticated()) {
					return "phone/phone-index";
				}else {
					return "phone/phone-login";
				}
			}
			if(currentUser.isAuthenticated()) {
				return "web/index";
			}
			return "web/login";
		}
		/**
	 * 注册页面跳转
	 * @return
	 */
	@RequestMapping("/toSuccess")
	public String toSuccess() {
		return "success";
	}
	@RequestMapping("/toIndex")
	public String toIndex() {
		return "phone/phone-index";
	}
	@RequestMapping("/toPath")
	public String toPath(String path) {
		logger.info("跳转：{}",path);
		return path;
	}
	@RequestMapping("/toSign")
	public String toSign() {
		return "phone/phone-sign";
	}
}
